home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: Reading directory into array of some kind.
- Date: 12 Feb 1996 16:42:12 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824160386@pegasus.montclair.edu>
- References: <4fis2r$tc7@news1.sunbelt.net>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- dking@SunBelt.Net writes:
-
- >The following bit of code uses the findfirst/findnext to read all the
- >filesname out of the current directory. I had HOPED to be able to put the file
- >names into some sort of array but couldn't find a way to make it work.
-
- _dos_findfirst() and _dos_findnext() aren't specified in ANSI C. In fact,
- they're not even that portable across PC platforms. That being said,
-
- >Any help on this would be greatly appreciated.
-
- ... I don't see any reason not to help anyway. :) The point of interest
- is that the ffblk structure returned by findfirst() (and its brethren, but
- findfirst() is at least more PC-portable) includes a char name[13] member.
- When we leave off the []'s, name devolves into a pointer to a char (name[0]).
- So what we have for lack of technical specificity, is a "string." To work
- with strings, you should include the standard <string.h> header in your file.
- Here are my suggestions, the extension of saving these names into your array
- is straightforward.
-
-
- >#include <stdio.h>
- >#include <dos.h>
- :#include <string.h>
-
- >int main()
- >{
- >
- > struct find_t ffblk;
- > int done;
- : char filename[13];
- >
- > printf("Directory listing \n");
-
- > done = _dos_findfirst("*.*",255,&ffblk); //reads all files from directory
- > while (!done)
- > {
- : strcpy(filename, ffblk.name); // filename <- ffblk.name
- > printf(" %s\n", ffblk.name); //print file names
- > done = _dos_findnext(&ffblk);
- > }
-
- > return 0;
- >}
-
- That should do it. :) Always know your standard C library better than
- your DOS-specific one.
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... Tadpoles turn into Frogs. What do frogs turn into?
-